import * as mobx from 'mobx';
import { observable, action } from 'mobx';
import * as API_REQ from '../apis/req';

export class PrintReqStore{

    urlParams = {};
    @observable needChoose = false;
    templates = [];
    @observable templateKey = "";

    constructor(){
        this.loadTemplates = this.loadTemplates;
        this.chooseTemplate = this.chooseTemplate;
    }

    @action('加载模板列表')
    loadTemplates = (urlParams) => {
        this.urlParams = urlParams;
        API_REQ.loadPrintTemplates(urlParams).then(data =>{
            const { needChoose,templates } = data;
            this.needChoose = needChoose;
            this.templates = templates;
            if(templates.length > 0)
                this.chooseTemplate(templates[0].key);
        });
    }

    @action('选中模板')
    chooseTemplate = (key) => {
        this.templateKey = key;
    }

}